package com.zjj.learn.javaplus.pkg07.demo701;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

public class TCPServer {

    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(9699);
        Socket socket = serverSocket.accept();
        InputStream is = socket.getInputStream();
        byte[] buf = new byte[1024];
        int i = is.read(buf);

        System.out.println("客户端发送：" + new String(buf, 0, i));

        OutputStream os = socket.getOutputStream();
        os.write("约你妹".getBytes(StandardCharsets.UTF_8));
        //关闭 Socket
        socket.close();
        //关闭 ServerSocket
        serverSocket.close();
    }
}
